package cn.itsource.ymcc.feign;


import cn.itsource.result.JSONResult;
import feign.hystrix.FallbackFactory;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@FeignClient(value = "service-media",fallbackFactory = MediaFileClientFallbackFactory.class)
public interface MediaFileClient {

    @RequestMapping(value = "/mediaFile/queryByCourseId/{courseId}",method = RequestMethod.GET)
    JSONResult queryByCourseId(@PathVariable("courseId") Long courseId);
}

@Component
class MediaFileClientFallbackFactory implements FallbackFactory<MediaFileClient> {
    @Override
    public MediaFileClient create(Throwable throwable) {
        return new MediaFileClient() {
            @Override
            public JSONResult queryByCourseId(Long courseId) {
                throwable.printStackTrace();
                return JSONResult.error("媒体微服务不可达。。。。");
            }
        };
    }
}
